/* The structures according to graph description language

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */

#ifndef G_H
#define G_H

#include <assert.h>


typedef struct g_node g_node;
typedef struct g_edge g_edge;
typedef struct g_graph g_graph;

enum gdl_node_attr
{
  G_NODE_ATTR_bordercolor,
  G_NODE_ATTR_borderwidth,
  G_NODE_ATTR_color,
  G_NODE_ATTR_horizontal_order,
  G_NODE_ATTR_label,
  G_NODE_ATTR_title,
  G_NODE_ATTR_vertical_order,
  G_NODE_ATTR_MAX
};

struct g_node
{
  char *bordercolor;
  int borderwidth;
  char *color;
  int horizontal_order;
  char *label;
  char *title;
  int vertical_order;
  /* The value is 1 if the attribute is set.  */
  int set_p[G_NODE_ATTR_MAX];

  g_node *next;

  /* The graph who it belongs to.  */
  g_graph *parent;
};

typedef enum
{
  G_EDGE,
  G_BACKEDGE,
} g_edge_type;

enum g_edge_attr
{
  G_EDGE_ATTR_label,
  G_EDGE_ATTR_linestyle,
  G_EDGE_ATTR_sourcename,
  G_EDGE_ATTR_targetname,
  G_EDGE_ATTR_thickness,
  G_EDGE_ATTR_MAX
};

struct g_edge
{
  char *label;
  char *linestyle;
  char *sourcename;
  char *targetname;
  int thickness;
  /* The value is 1 if the attribute is set.  */
  int set_p[G_EDGE_ATTR_MAX];

  g_edge_type type;
  g_edge *next;
};

enum g_graph_attr
{
  G_GRAPH_ATTR_color,
  G_GRAPH_ATTR_colorentry,
  G_GRAPH_ATTR_folding,
  G_GRAPH_ATTR_label,
  G_GRAPH_ATTR_layout_algorithm,
  G_GRAPH_ATTR_near_edges,
  G_GRAPH_ATTR_node_alignment,
  G_GRAPH_ATTR_orientation,
  G_GRAPH_ATTR_port_sharing,
  G_GRAPH_ATTR_shape,
  G_GRAPH_ATTR_splines,
  G_GRAPH_ATTR_title,
  G_GRAPH_ATTR_vertical_order,
  G_GRAPH_ATTR_xspace,
  G_GRAPH_ATTR_yspace,

  G_GRAPH_ATTR_node_borderwidth,
  G_GRAPH_ATTR_node_color,
  G_GRAPH_ATTR_node_shape,
  G_GRAPH_ATTR_node_textcolor,

  G_GRAPH_ATTR_edge_color,
  G_GRAPH_ATTR_edge_thickness,
  G_GRAPH_ATTR_MAX
};

struct g_graph
{
  char *color;
  int colorentry[256][3];
  int folding;
  char *label;
  char *layout_algorithm;
  char *near_edges;
  char *node_alignment;
  char *orientation;
  char *port_sharing;
  char *shape;
  char *splines;
  char *title;
  int vertical_order;
  int xspace;
  int yspace;

  int node_borderwidth;
  char *node_color;
  char *node_shape;
  char *node_textcolor;

  char *edge_color;
  int edge_thickness;
  /* The value is 1 if the attribute is set.  */
  int set_p[G_GRAPH_ATTR_MAX];
  int colorentry_set_p[256];

  /* nodes or subgraphs */
  int node_num;
  int subgraph_num;
  int edge_num;
  g_node *node;
  g_node *last_node;
  g_graph *subgraph;
  g_graph *last_subgraph;
  g_edge *edge;
  g_edge *last_edge;
  g_graph *next;
  /* The graph who it belongs to.  */
  g_graph *parent;
};

/* Free the GRAPH.  */
extern void
g_free_graph (g_graph *graph);

/* Dump GRAPH into the file.  */
extern void
g_dump_graph (FILE *fout, g_graph *graph);

/* Create a graph for a given TITLE.  */
extern g_graph *
g_new_graph (char *title);

#endif

/* end */
